import 'dart:math';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class LotteryPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _LotteryPageState();
  }
}

class _LotteryPageState extends State<LotteryPage> {
  String _lotteryQiXi = '';
  String _lotteryDaLeTou = '大乐透';
  List<List<String>> winList = [];
  final List<String> winning = ['11', '15', '18', '20', '27', '05', '06'];

  static const List<String> _daLeTouNormal = [
    '01',
    '02',
    '03',
    '04',
    '05',
    '06',
    '07',
    '08',
    '09',
    '10',
    '11',
    '12',
    '13',
    '14',
    '15',
    '16',
    '17',
    '18',
    '19',
    '20',
    '21',
    '22',
    '23',
    '24',
    '25',
    '26',
    '27',
    '28',
    '29',
    '30',
    '31',
    '32',
    '33',
    '34',
    '35'
  ];
  static const List<String> _daLeTouLast = [
    '01',
    '02',
    '03',
    '04',
    '05',
    '06',
    '07',
    '08',
    '09',
    '10',
    '11',
    '12'
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('lottery'),
      ),
      body: _body(),
    );
  }

  _body() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.center,
//      mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
        RaisedButton(
          child: Text('七星彩'),
          onPressed: () {
            _qixingcai();
          },
        ),
        Container(
          alignment: Alignment.center,
          child: Text(
            _lotteryQiXi,
            textAlign: TextAlign.center,
            style: TextStyle(
              fontSize: 25,
              color: Colors.blue,
            ),
          ),
        ),
        RaisedButton(
          child: Text('大乐透'),
          onPressed: () {
            _daLeTou();
          },
        ),
        Container(
          alignment: Alignment.center,
          child: Text(
            winning.toString(),
            textAlign: TextAlign.center,
            style: TextStyle(
              fontSize: 25,
              color: Colors.redAccent,
            ),
          ),
        ),
        Expanded(
          flex: 1,
          child: ListView.builder(
            itemBuilder: (context, index) {
              return Container(
                alignment: Alignment.center,
                child: Text(
                  winList[index].toString(),
                  textAlign: TextAlign.center,
                  style: TextStyle(
                    fontSize: 25,
                    color: Colors.blue,
                  ),
                ),
              );
            },
            itemCount: winList.length,
          ),
        ),
      ],
    );
  }

  _qixingcai() {
    Random random = Random();
    _lotteryQiXi = '';
    for (int i = 0; i < 7; i++) {
      setState(() {
        _lotteryQiXi += random.nextInt(9).toString();
      });
    }
  }

  List<String> _daLeTouSingle() {
    List<String> list = [];
    Random random = Random();
    for (int i = 0; i < 5; i++) {
      list.add(_daLeTouNormal[random.nextInt(35)]);
    }
    list.add(_daLeTouLast[random.nextInt(12)]);
    list.add(_daLeTouLast[random.nextInt(12)]);
    return list;
  }

  _daLeTou() {
    winList.clear();
    for (int i = 1; i <= 10; i++) {
      List<String> item = _daLeTouSingle();
      setState(() {
        winList.add(item);
      });
    }
  }
}
